{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import panel as pn\n",
    "pn.extension()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A ``ToggleGroup`` is a group of widgets which can be switched 'on' or 'off'.  \n",
    "\n",
    "This widget is a thin wrapper for using either a [CheckButtonGroup](CheckButtonGroup.ipynb), [CheckBoxGroup](CheckBoxGroup.ipynb), [RadioButtonGroup](RadioButtonGroup.ipynb) or [RadioBoxGroup](RadioBoxGroup.ipynb) to select between a single or multiple given values.\n",
    "\n",
    "Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](../../how_to/interactivity/index.md). Alternatively, learn [how to set up callbacks and (JS-)links between parameters](../../how_to/links/index.md) or [how to use them as part of declarative UIs with Param](../../how_to/param/index.md).\n",
    "\n",
    "#### Parameters:\n",
    "\n",
    "For details on other options for customizing the component see the [layout](../../how_to/layout/index.md) and [styling](../../how_to/styling/index.md) how-to guides.\n",
    "\n",
    "##### Core\n",
    "\n",
    "* **``widget_type``** (str): Two types of widgets are available: ``button`` (default) and ``box``\n",
    "* **``behavior``** (str): Two different behaviors are available: ``check`` (default) and ``radio``\n",
    "\n",
    "\n",
    "As the `ToggleGroup` class is just a Factory for other different widget types, the above parameters cannot be changed or set after instantion.\n",
    "All additional given parameters are passed through to the constructor of the resulting widget class.\n",
    "\n",
    "The different parameter combinations and the resulting widget type are shown in the following table.\n",
    "\n",
    "| widget_type | behavior  | Resulting Widget  |\n",
    "|---|---|---|\n",
    "| button  | check  |  [CheckButtonGroup](CheckButtonGroup.ipynb) |\n",
    "| button  | radio  |  [RadioButtonGroup](RadioButtonGroup.ipynb) |\n",
    "|  box | check  |  [CheckBoxGroup](CheckBoxGroup.ipynb) |\n",
    "| box  |  radio | [RadioBoxGroup](RadioBoxGroup.ipynb)  |\n",
    "\n",
    "\n",
    "___"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "toggle_group = pn.widgets.ToggleGroup(name='ToggleGroup', options=['Biology', 'Chemistry', 'Physics'])\n",
    "\n",
    "toggle_group"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Like most other widgets, ``ToggleGroup`` has a value parameter that can be accessed or set:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "toggle_group.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "toggle_group = pn.widgets.ToggleGroup(name='ToggleGroup', options=['Biology', 'Chemistry', 'Physics'], behavior=\"radio\")\n",
    "\n",
    "toggle_group"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For radio behavior the value is only a single value!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "toggle_group.value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The resulting object is not of type ToggleGroup but is an object dependent of the input parameters as shown in the `Parameters` section"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(toggle_group)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Controls\n",
    "\n",
    "The `ToggleGroup` widget (concretely the created, underlying widget) exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pn.Row(toggle_group.controls(jslink=True), toggle_group)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
